package bravo.xc.com.xc_bravo_android.operation.bankcard.bankcard;

import android.util.Log;

import bravo.xc.com.xc_bravo_android.beans.CommonBeans;
import bravo.xc.com.xc_bravo_android.beans.GetCardResultBeans;
import bravo.xc.com.xc_bravo_android.http.HttpSingleton;
import bravo.xc.com.xc_bravo_android.http.UserOperationService;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * CREATED BY YANK
 * DATE : 2017/11/5
 * MAIL : YANK.TENYOND@GMAIL.COM
 * FUNCTION :
 */

public class BankCardPresenter extends BankCardContract.BankCardPresenter {

    private UserOperationService userOperationService ;

    @Override
    public void getCard(CommonBeans commonBeans) {
        Log.e("@@getCard",commonBeans.getUserId());
        userOperationService = HttpSingleton.getInstance().service;
        compositeSubscription.add(userOperationService.getCard(commonBeans)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<GetCardResultBeans>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                        Log.e("@@onError",String.valueOf(e));
                        view.showToast("网络错误，请重试");
                    }

                    @Override
                    public void onNext(GetCardResultBeans getCardResultBeans) {
                        Log.e("onNext",String.valueOf(getCardResultBeans.getCode()));
                        if(getCardResultBeans.getCode() == 1){
                            view.setAdapterData(getCardResultBeans);
                        }else {
                            view.showToast("出现未知错误");
                        }
                    }
                })
        );
    }
}
